package test_achieve.web;

import constant.Constant;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.List;
import java.util.TimeZone;

/**
 * Created by chenkuo on 2017/8/2.
 */
public class Method {

    /*判断当前时间是否为24:00至7:00*/
    public static boolean night(){
        boolean flag = false;
        long current = System.currentTimeMillis();//当前时间
        long zero=current/(1000*3600*24)*(1000*3600*24)- TimeZone.getDefault().getRawOffset();//今天零点零分零秒的毫秒数
        long seven =  zero + (7*60*60*1000);//早上七点
        if(zero>current&current<seven){
            flag=true;
            return flag;
        }
        return flag;
    }
    /*"当前页"订单数量*/
    public static int OrderQuantityToday(){
        List<WebElement> OrderQuantity = Constant.driverWeb.findElements(By.tagName("tr"));
        int OrderQuantitys = OrderQuantity.size() -2;
//        System.out.println("当前页有几个订单"+OrderQuantitys);
        return OrderQuantitys;
    }


    /**输出，从上至下第几个订单*/
    public static int  OrderLine(String orderNumbuter){
        int count =OrderQuantityToday();
        for (int i=1;i<count;i++){
            WebElement dds = Constant.driverWeb.findElement(By.xpath("//*[@id=\"container_wrapper\"]/div[1]/div[2]/table/tbody/tr["+i+"]"));
            String num = dds.getText().substring(0,19);
            if (orderNumbuter.equals(num)){
                return i;
            }
        }
        return 0;
    }

    /**今日订单列表字符查找()是否存在*/
    public static boolean qeuryAllOrderContent(String ordernumbuter,String Contant){
        System.out.println("传入的订单号:"+ordernumbuter);
        boolean flag = false;
        int count =OrderQuantityToday();
        for (int i=0;i<count;i++){
            WebElement dds = Constant.driverWeb.findElement(By.xpath("//*[@id=\"container_wrapper\"]/div[1]/div[2]/table/tbody/tr["+i+1+"]"));
            String num = dds.getText().substring(0,19);
//            System.out.println("当前页找到的订单号："+num);
            if (ordernumbuter.equals(num)){
//                System.out.println("I值是多少："+i+1);
                return dds.getText().contains(Contant);
            }
        }
        return  flag;
    }

}
